package com.jieyang.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jieyang.oa.dao.PaymentDao;
import com.jieyang.oa.pojo.Vo.ExpenseListVo;
import com.jieyang.oa.pojo.entity.Payment;
import com.jieyang.oa.service.PaymentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 29276
 * @version 1.0
 * @description: TODO
 * @date 2021/8/26 21:58
 */
@Service
@Transactional
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentDao paymentDao;

    @Override
    public Integer insert(Payment payment) {
        return paymentDao.insert(payment);
    }

    @Override
    public PageInfo<ExpenseListVo> selectExpense(String startDate, String endDate, Long deptNo, String realName, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);

        List<ExpenseListVo> expenseListVo = paymentDao.selectExpense(startDate, endDate, deptNo, realName);

        PageInfo<ExpenseListVo> expenseListVoPageInfo = new PageInfo<>(expenseListVo);
        int ceil = (int) Math.ceil((paymentDao.count(startDate, endDate, deptNo, realName)*1.0)/pageSize);
        expenseListVoPageInfo.setPages(ceil);
        expenseListVoPageInfo.setSize(paymentDao.count(startDate, endDate, deptNo, realName));
        return expenseListVoPageInfo;
    }
}
